package nus.mtech.user;

import java.util.ArrayList;
import java.util.Iterator;

import nus.mtech.util.LoadConfig;

public class AuthenticationManager {
	private static AuthenticationManager authenMgr;
    private LoadConfig config;
    private ArrayList<User> userList = new ArrayList<User>();
	public ArrayList<User> getUserList() {
		return userList;
	}

	public void setUserList(ArrayList<User> userList) {
		this.userList = userList;
	}

	public static AuthenticationManager getInstance(){
		if (authenMgr == null)
			authenMgr = new AuthenticationManager();
		return authenMgr;
	}
	
	public User login(String userName, String password){
		return validateUser(userName, password);
	}
	
	
	public User validateUser(String id, String password) {
		Iterator<User> iter = this.getUserList().iterator();
		
		while (iter.hasNext()) {
			User user = (User) iter.next();
			if (user.getUserID().equals(id) && user.getPassword().equals(password)) {
				return user;
			}
		}
		return null;
	}
	
    
	private AuthenticationManager(){
		 config = new LoadConfig();
	}
}
